<?php
/**
 * Edition d'une liste de traduction
 */
require_once("include/setup.php");
require_once(CLASS_PATH.'translation.list.class.php');
require_once(CLASS_PATH.'translation.class.php');
LoginHelper::controlAccess(array('type_droits_user' => '>=1'));

$list = new Translation_List($_REQUEST['id']);

if (!empty($list->id_list)) {
	LoginHelper::controlAccess(array('id_user' => $list->id_user));
}
$error = false;
if (!empty($_POST['list'])) {

	$data = $_POST['list'];
	$list = new Translation_List($data['id_list']);
	$list->init($data);
	if (!isset($data['shared'])) {
		$list->shared = false;
	}
	
	if (empty($list->libelle)) {
		Notification::add(Notification::$ERROR, "Merci de renseigner un nom pour la liste");
		$error = true;
	}
	$list->id_user = LoginHelper::getIdUserConnected();
	if (!$error && $list->save()) {
		Notification::add(Notification::$SUCCESS, "La liste a été enregistrée.");
	}
	else if (!$error) {
		Notification::add(Notification::$ERROR, "Impossible de créer une nouvelle liste.");
	}
}

$v = new JapwordView();
$v->assign('list', $list);
$v->addNotifications();
$v->assign('breadcrumb',array(
	"Mes listes" => 'translation_list_mylist.php',
	"Liste de mot" => ''
));

if (!empty($list->id_list)) {
	$new_translations = Translation::getTranslations(array(
		'withTerm' => true,
		'orderby' => 'translations.last_update, terms.kana',
		'notids' => $list->getIdsTranslation(),
		'limit' => 30
	));
	$v->assign('translations_in_list', $list->getTranslations());
	$v->assign('new_translations', $new_translations);
	$v->display('translation_list_edit.html');
}
else {
	$v->display('translation_list_add.html');
}
?>